//
//  SinaRetweenView.swift
//  weibo
//
//  Created by sirius on 16/1/6.
//  Copyright © 2016年 sirius. All rights reserved.
//

import UIKit
import SnapKit

class SinaRetweenView: UIView {
    //定义一个属性底部约束
    var picConstainty: Constraint?
    
    var retweetViewMode: SinaStatusViewModel?{
        didSet{
            contentLabel.text = retweetViewMode?.model?.retweeted_status?.text
            
            //判断数据源---转发微博的配图 在转发的模型里
            //消失底部约束的重用影响
            picConstainty?.uninstall()
            if retweetViewMode?.model?.retweeted_status?.pic_urls?.count > 0{
                //根据数据源，实现配图的隐藏或者显示
                pictureView.hidden = false
                
                snp_updateConstraints(closure: { (make) -> Void in
                picConstainty = make.bottom.equalTo(pictureView.snp_bottom).constraint
                })
                pictureView.pictures = retweetViewMode?.model?.retweeted_status?.pic_urls
            }else{
                snp_updateConstraints(closure: { (make) -> Void in
                    picConstainty = make.bottom.equalTo(contentLabel.snp_bottom).constraint
                    
                })
                pictureView.hidden = true
            }
         }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("error")
    }
    private func setupUI(){
        addSubview(contentLabel)
        addSubview(pictureView)
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(contentLabel.snp_bottom)
         }
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            
            make.width.equalTo(self.snp_width)
        }
        //告诉转发微博的底部到contentLabel的底部
        self.snp_makeConstraints { (make) -> Void in
           picConstainty = make.bottom.equalTo(contentLabel.snp_bottom).constraint
        }
    }
    //懒加载
    lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(19)
        label.shadowColor = UIColor.magentaColor()
        label.shadowOffset = CGSizeMake(3, -3)
        label.numberOfLines = 0
        return label
    }()
    //MARK:-------1.懒加载一个配图
    lazy var pictureView: SinaPictureView = SinaPictureView()

}
